package com.freewater.javabase.demo.designpattern.vistor;

import java.util.ArrayList;
import java.util.List;

// 具体元素 - 计算机（对象结构）
public class Computer implements ComputerPart {

    private final List<ComputerPart> parts;

    public Computer() {
        parts = new ArrayList<>();
        parts.add(new Mouse());
        parts.add(new Keyboard());
        parts.add(new Monitor());
    }

    @Override
    public void accept(ComputerPartVisitor computerPartVisitor) {
        for (ComputerPart part : parts) {
            part.accept(computerPartVisitor);
        }
        computerPartVisitor.visit(this);
    }
}
